package Tables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class Student extends Table{
    private int id;
    private String name;
    private int class_id;
    private double all_credits;
    public Student(Connection connection) {
        super(connection);
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", class_id=" + class_id +
                ", all_credits=" + all_credits +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getClass_id() {
        return class_id;
    }

    public void setClass_id(int class_id) {
        this.class_id = class_id;
    }

    public double getAll_credits() {
        return all_credits;
    }

    public void setAll_credits(double all_credits) {
        this.all_credits = all_credits;
    }

    @Override
    public List<String> get() throws SQLException {
        String order = "select * from student";
        PreparedStatement statement = this.connection.prepareStatement(order);
        ResultSet set = statement.executeQuery();
        while(set.next()){
            this.id = set.getInt(1);
            this.name = set.getString(2);
            this.class_id = set.getInt(3);
            this.all_credits = set.getDouble(4);
            this.tableList.add(toString());
        }
        return this.tableList;
    }
}
